#ifndef __SMART_POINTER_H__
#define __SMART_POINTER_H__

#include "Common.h"

NAME_SPACE_BEGIN


template<typename T>
class SmartPointer : public Object
{
	using value_type = T;
	using pointer = T*;
	using const_pointer = const T*;
	using reference = T&;
	using const_reference = const T&;

	using self_reference = SmartPointer<T>&;
	using const_self_reference = const SmartPointer<T>&;



public:
	SmartPointer(T* p = nullptr) {
		m_pointer = p;
	}

	SmartPointer(const_self_reference obj) {
		m_pointer = obj.m_pointer;
		const_cast<self_reference>(obj).m_pointer = nullptr;
	}

	self_reference operator=(const_self_reference obj) {
		if (this != &obj)
		{
			delete m_pointer;
			m_pointer = obj.m_pointer;
			const_cast<reference>(obj).m_pointer = nullptr;
		}
	}

	~SmartPointer() {
		delete m_pointer;
	}

	pointer operator->() {
		return m_pointer;
	}

	reference operator*() {
		return *m_pointer;
	}

	pointer get() {
		return m_pointer;
	}


	bool isNull() {
		return nullptr == m_pointer;
	}

protected:
	pointer m_pointer;
};



NAME_SPACE_END


#endif
